import React, { Component } from 'react';
import { Icon, Button, Table, Popconfirm, Switch, Form, Input } from 'antd';
import { IndexLink, Link } from 'react-router';

import styles from './wilddog.less';
import  EditableCell from './EditableCell';
import  AddInput from './AddInput';



export class RoomList extends Component {
  constructor(props) {
    super(props);
    console.log(props)
  }

 addOneRoomHandler(name) {
   let { auth } = this.props;
    let payload = {
      createdByUserId: auth.uid,
      name: name,
      type: 'public'
    }
    if (payload.type === 'private') {
      console.log('私有聊天室');
    }
    this.props.addOneRoom(payload)
  }
 
  onChange(pagination, filters, sorter) {
    // console.log('params', pagination, filters, sorter);
  }
   tableExpandedRowRender(record) {
    let { authorizedUsers, userInfo } = record;
    let userList = authorizedUsers ? Object.keys(authorizedUsers) : [];
    userInfo ? null : this.props.getUser(record.createdByUserId);

    return (
      <div className="room-userList">
         {userInfo?( <div className="room-userList-create flexItem">

            <div className="room-userList-photo"><img src={userInfo.photo} alt=""/></div>
            <div className="room-userList-name">{userInfo.name}</div>
          </div>):<div className="room-userList-create flexItem">Loading</div>}
          <div className="room-userList-authorized flexItem">
           <Button type="dashed"  onClick={this.authorizeHandler.bind(this,record)} >
            <p><Icon type="plus" style={{lineHeight:4}} /> </p>
            <p>添加一个授权者</p>
          </Button>
          </div>
        </div>
    )
  }
  render() {
    const {roomList}=this.props;
      const columns = [{
      title: '留言名称',
      dataIndex: 'name',
      key: 'name',
      width: '20%',
      render: text => <span className="cellItem_name">{text}</span>,
    }, {
      title: '创建时间',
      dataIndex: 'createdAt',
      key: 'createdAt',
      sorter: (a, b) => a.createdAt - b.createdAt,
      render: (text) => {
        let newDate = new Date();
        newDate.setTime(text);
        return <p>{newDate.toLocaleDateString("zh-cn",{weekday: "long", year: "numeric", month: "long", day: "numeric","hour": "numeric","minute":"numeric"})}</p>
      },
    },{
      title: '房间ID',
      dataIndex: 'id',
      key: 'roomid',
    },  {
      title: '查看',
      dataIndex: 'id',
      key: 'id',

      render: (text, record, index) => (<div className="setting">
                                        <p>
                                         {this.props.auth.status?
                                            <Button type="primary"> 
                                                <Link to={{pathname:`/wilddog/room/${record.id}`}} >
                                                  管理留言
                                                </Link>
                                             </Button>: <span>暂无权限</span>
                                          
                                       }
                                        </p>
                                      </div>)
    },  {
      title: '留言数',
      dataIndex: 'id',
      key: 'count',

      render: (text, record, index) => (<div >
                                        暂时无法获取 
                                      </div>)
    }];

    return (
     <div>
      <AddInput handAdd= {this.addOneRoomHandler.bind(this)}/>
      <Table    simple  
                className={styles.table} 
                bordered 
                scroll={{x: 1200 }}            
                columns={columns} 
                dataSource={roomList||[]}
                rowKey={record => record.id} 
                    />
    </div>

    )
  }
}


export default RoomList
